package com.study.sbsummary.utils.i18n;

import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Optional;
import java.util.ResourceBundle;

public class I18nUtil {
    public static String getLocalizedString(Locale locale, String base,
                                            String key) {
        locale = Optional.ofNullable(locale).orElse(Locale.getDefault());
        ResourceBundle resourceBundle = ResourceBundle.getBundle(base, locale);
        return new String(resourceBundle.getString(key).getBytes(StandardCharsets.UTF_8));
    }
}
